import java.awt.Color;
import java.awt.Point;
import java.awt.geom.Line2D;

public class Line {
	
	public Point start;
    public Point end;
    public Color color;
    public int A;
    public int B;
    public int C;
    public Line (Point st, Point en){
    	this.start = st;
    	this.end = en;
    	color = Color.BLACK;
    }
    public Line (){
    	
    }
    public void move(int dx, int dy, boolean fst) {
    	if (fst) {
    		start.x += dx;
    		start.y += dy;
    	}
    	end.x += dx;
    	end.y += dy;
    }
    public void getABC(){
    	A = end.y - start.y;
    	B = end.x - start.x;
    	C = end.x * start.y - start.x * end.y;
    }
    public float distToPoint (Point p) {
    	Vector vl1 = new Vector (this.start, this.end);
    	Vector vp1 = new Vector (this.start, p);
    	Vector vl2 = vl1.revert();
    	Vector vp2 = new Vector (this.end, p);
    	if (vl1.obtuseAngle(vp1)) return vp1.d;
    	else if (vl2.obtuseAngle(vp2)) return vp2.d;
    	else {
    		getABC();
    		int sgnC = -1;
    		if (C != 0) sgnC = C / Math.abs(C); 
    		float mu = (-1) * sgnC / vl1.d;
    		float ret = mu * (A * p.x - B * p.y + C);
    		return Math.abs(ret);
    	}    	
    }
}
